package cn.com.scooper.utils;

import java.security.AlgorithmParameters;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Base64;

/**
 * 
* @ClassName: AES128CBCwithPKCS5 
* @Description: AES128加密解密工具类
* @author luoxiao
* @date 2021年7月5日 下午2:47:17 
*
 */
public class AES128CBCwithPKCS5Utils {

	/**
	 * 
	* @Title: encrypt 
	* @Description: 加密算法
	* @param @param data  加密数据
	* @param @param sKey  密钥
	* @param @param iv    初始向量
	* @param @return    设定文件 
	* @return String    返回类型 
	* @throws
	 */
	public static String encrypt(String data, String sKey, String iv){
		try {
            //创建AES的密钥
            SecretKeySpec aesKey = new SecretKeySpec(sKey.getBytes("UTF-8"), "AES");
            //初始向量
            IvParameterSpec ivPara = new IvParameterSpec(iv.getBytes("UTF-8"));
            //加密 模式 填充方式
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
            cipher.init(Cipher.ENCRYPT_MODE, aesKey, ivPara);
            byte[] encrypt = cipher.doFinal(data.getBytes());
            return new String(Base64.encodeBase64(encrypt));//此处使用BASE64做转码功能，同时能起到2次加密的作用。  
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
	}
	
	/**
	 * 
	* @Title: decrypt 
	* @Description: 数据解密
	* @param @param data  解密数据
	* @param @param sKey  密钥
	* @param @param iv    向量
	* @param @return    设定文件 
	* @return String    返回类型 
	* @throws
	 */
	public static String decrypt(String data, String sKey, String iv){
		try{
			byte[] decryData = Base64.decodeBase64(data);
			Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
			Key sKeySpec = new SecretKeySpec(sKey.getBytes(), "AES");
			cipher.init(Cipher.DECRYPT_MODE, sKeySpec, generateIV(iv.getBytes()));// 初始化
			byte[] result = cipher.doFinal(decryData);
			return new String(result,"UTF-8");
		}catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 
	* @Title: generateSkey 
	* @Description: 随机生成密钥 
	* @param @return    设定文件 
	* @return String    返回类型 
	* @throws
	 */
	public static String generateSkey(){
		try{
			KeyGenerator kg = KeyGenerator.getInstance("AES");
			kg.init(128);
			SecretKey sk = kg.generateKey();
			byte[] b = sk.getEncoded();
			String s = byteToHexString(b);
			return s;
		}catch(NoSuchAlgorithmException e){
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 
	* @Title: generateSkey 
	* @Description: 使用指定字符串生成密钥 
	* @param @param target
	* @param @return    设定文件 
	* @return String    返回类型 
	* @throws
	 */
	public static String generateSkey(String target){
		try{
			KeyGenerator kg = KeyGenerator.getInstance("AES");
			kg.init(128, new SecureRandom(target.getBytes()));
			SecretKey sk = kg.generateKey();
			byte[] b = sk.getEncoded();
			String s = byteToHexString(b);
			return s;
		}catch(NoSuchAlgorithmException e){
			throw new RuntimeException(e);
		}
	}
	
	public static String generateIV(String target){
		return Base64.encodeBase64String(target.getBytes()).substring(0, 16);
	}
	
	public static String byteToHexString(byte[] bytes) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < bytes.length; i++) {
			String strHex=Integer.toHexString(bytes[i]);
			if(strHex.length() > 3) {
				sb.append(strHex.substring(6));
			} else {
				if(strHex.length() < 2) {
					sb.append("0" + strHex);
				} else {
					sb.append(strHex);
				}
			}
	
		}
		return sb.toString();
	}
	
	// 生成iv
    private static AlgorithmParameters generateIV(byte[] iv) throws Exception {
        AlgorithmParameters params = AlgorithmParameters.getInstance("AES");
        params.init(new IvParameterSpec(iv));
        return params;
    }
     
    public static void main(String[] args) {
    	String sKey = generateSkey("528FC3DFFCDDE944E2E225C7A38BF838");
        String cKey = generateIV(sKey);
//        System.out.println("AES加密密钥:"+sKey);
//        System.out.println("AES加密向量:"+cKey);
		String str = "{\"dataId\":\"1563259577529\",\"enterpriseId\":\"1441615777852455\",\"gatewayId\":\"123456789\","
				+ "\"collectTime\":\"20180615123456\",\"isConnectDataSource\":true,\"reportType\":\"report\",\"datas\":[{\"quotaId\":\"123\",\"value\":123.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"},{\"quotaId\":\"123\",\"value\":223.0,\"alarmType\":\"alarmhi:alarm\",\"threshold\":7,\"alarmTime\":\"20180615123456\"}]}";
        String result = encrypt(str,sKey,cKey);
//        System.out.println("加密后的数据:"+result);

        result = "";
        sKey = "f5034e94d280401aa36aee7960c10029";
        cKey = "ZjUwMzRlOTRkMjgw";
        System.out.println("解密后的数据:"+decrypt(result,sKey,cKey));
    }
}
